/**
 * Created by GP on 2016/5/8.
 */

$(function(){

    $(".checkout").attr("disabled","disabled");

    $("[name='compute']").click(function(){
        $(".checkout").removeAttr("disabled");
        var intime = new Date($(".intime").val().replace("-","/").replace("-","/"));
        var discount = $(".discount").html();
        var price = $(".price").html();
        var deposit = $(".deposit").html();
        var dateTime =new Date($(".dateTime").val().replace("-","/").replace("-","/"));

        var dif = dateTime.getTime() - intime.getTime();
        var liveTime;
        //判断是普通入住还是 钟点房入住
        var liveType = $("[name='liveType']").val();
        if (liveType == "normal") {
            liveTime = (dif / (1000 * 60 * 60 * 24)).toFixed(2);
        } else {
            liveTime = (dif / (1000 * 60 * 60 )).toFixed(2);
        }

        var money = (liveTime * price * discount).toFixed(2);
        $(".money").html(money);
        $("[name='money']").val(money);
        $("[name='liveTime']").val(liveTime);
        var shouldpay = (deposit - money).toFixed(2);
        if (shouldpay > 0){
            $(".pay").html("退款 :" + shouldpay + " 元");
        } else {
            $(".pay").html("补交 :" + shouldpay * -1 + " 元");
        }
    });
});


